<?php

namespace app\index\controller;

use library\Controller;
use app\common\model\SystemPointDetailed;
use app\index\service\ExportService;
use think\Db;

/**
 * 收支明细
 * Class Payment
 * @package app\index\controller
 */
class Payment extends Base
{
    /**
     * 明细列表
     */
    public function index()
    {
    	$where[] = ['mid','eq',$this->company['mid']];
		$type = $this->request->get('type');
        if($type){
        	if($type == 1){
        		$where[] = ['type','in',[2,4]];
        	}
			if($type == 2){
        		$where[] = ['type','eq',3];
        	}
			if($type == 3){
        		$where[] = ['type','eq',1];
        	}
        }   
		$search =  $this->request->get('search');
		if($search){
			$where[] = ['code|desc','like','%'.$search.'%'];
		}  
    	$list = SystemPointDetailed::where($where)
				->field('id,code,type,point,desc,create_at')
    			->order('id desc')
    			->paginate(10,false,['query'=>request()->param(),'type' => 'page\Page','var_page'  => 'page']);
		foreach($list as $k=>$v){
			if(in_array($v['type'], [1,3])){
				$list[$k]['point'] = '+'.$v['point'];
			}else{
				$list[$k]['point'] = '-'.$v['point'];
			}
    		$list[$k]['create_at'] = date('Y-m-d H:i',$v['create_at']); 		
    	}
        $this ->list = $list; 	
        $this->fetch();
    }


	/**
     * 导出
     */
    public function export()
    {
        $data = $this->request->param();
    	$ids = explode(',', $data['id']);
		$list = ExportService::export_point_detail($ids,$this->company['mid']);
    	toexcel($list['filename'],$list['titles'],$list['list']);  
    }
	
	
}
